var reDigits = /^\d+$/;

if (window.addEventListener) 
	window.addEventListener('load',inicializa,false); 
else if (document.addEventListener) 
	document.addEventListener('load',inicializa,false); 
else if (window.attachEvent) 
	window.attachEvent('onload',inicializa); 
else {//Older browsers only 
if (typeof window.onload=='function') { 
	var oldload=window.onload; 
	window.onload=function(){ 
	oldload(); 
	inicializa(); 
	} 
} else 
	window.onload=inicializa; 
}
function submitaForm(form,action,controller,func){
	espera();
	if(func != null){
		func();
	}
	document.getElementById(form).action = '/' +controller + '/' + action;
	document.getElementById(form).submit();
}
function inicializa(){
	FocusFirstFormComponent();
	for (var i=0;i<document.forms.length;i++){
		for(var j=0;j<document.forms[i].elements.length;j++){
			oField = document.forms[i].elements[j];
			//oField.style.textTransform = "uppercase";
		}
	}
	if(document.getElementById('carregando') != null){
		document.getElementById('carregando').style.display = 'none';
	}
}

function espera(){
	if(document.getElementById('carregando') != null){
		document.getElementById('carregando').style.display = 'block';
	}
}

function FocusFirstFormComponent(){
	var oField;
	if (document.forms.length > 0){
		
		for(var i=0;i<document.forms[0].elements.length;i++){
			oField = document.forms[0].elements[i];
			if ((oField.type!= "hidden") && (oField.type != "select-one") && (oField.type != undefined)){
				if (oField.disabled!=true){
					oField.focus();
					break;
				}
			}
		}
	}
}